package com.letv.whatslive.model.dto;

import com.alibaba.fastjson.JSON;
import com.letv.whatslive.common.utils.Constants;
import com.letv.whatslive.common.utils.DateUtils;
import com.letv.whatslive.common.utils.ObjectUtils;
import com.letv.whatslive.model.ActivityInfo;
import com.letv.whatslive.model.Program;
import com.letv.whatslive.model.StreamInfo;
import com.letv.whatslive.model.User;
import com.letv.whatslive.model.constant.ProgramConstants;
import com.letv.whatslive.model.convert.UserConvert;
import com.letv.whatslive.model.redis.chat.protocol.ChatEvent;
import com.letv.whatslive.model.utils.Constant;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by gaoshan on 15-7-13.
 */
@Getter
@Setter
public class ProgramDTO {

    private Long id;
    private String pName;
    private String pDesc;
    private int pType;  //节目类型 1:直播 2:预约 3:点播
    private String picture;
    private String bigPicture; //大图封面
    private UserDTO user;  //发布人
    private String streamId;
    private String startTime;
    private String playTime;
    private Long watchNum; // 观看人数
    private Long watchCount; // 观看人次
    private Long likeNum;
    private Long commentNum;
    private Integer isSelf;  //判断是否是当前用户发起
    private Integer isReport; //直播被当前用户举报状态 1：已举报 0：未举报
    private Integer status;  //0：未预约 1：已预约
    private LiveInfo liveInfo;  //轮播台信息
    private ReplayInfo replayInfo; //录播节目信息
    private Integer from;
    private Integer isFocus;  //当前用户对直播发布人的关系
    private String shareUrl;  //直播分享地址
    private Integer ugcStatus;  //转码状态  -1正在转码，1转码完成
    private String actionLogUrl; //回放日志文件地址
    private Integer actionLogVer; //回放日志文件版本号
    private String provice; // 直播地址：省
    private String city; // 直播地址：市
    private ActivityDTO activity; // 活动信息
    private Long orderNum; //预约人数
    private String iconUrl; // 角标
    private String copyWriter; // 活动分享文案
    private String likeIconUrl;//点赞图标地址
    private String likeIconMd5;//点赞图标Md5值
    private Long userId;  //发布人id
    private String location; //直播发布的地理位置
    private Long realWatchNum; // 真实观看人数
    private Long realLikeNum; // 真实点赞数
    private Long realCommentNum; // 真实评论数
    private Long endTime;  // 结束时间
    private Long createTime; // 创建时间
    private Long updateTime; // 更新时间
    private Long displayOrderNum;//cms中维护的预约人数
    private Long priority; //优先级
    private Integer isShow = 1; //0：表示不显示，1：表示显示，是否在推荐中显示，默认为显示。
    private String primaryPName; //原始标题
    private Integer isCarousel; //是否是轮播台，1表示是，其他表示不是
    private String liveId; //轮播台LiveID
    private String activityId; //直播活动ID
    private String videoId; //录播视频ID
    private String vuid; //录播视频唯一标识，录播播放必须参数
    private Integer isContinue; //该直播是否可持续推流 1是，0否
    private List<ChatEvent> recentComment; // 最近的评论
    private String playUrl; // H5视频播放URL
    private String likeNumStr;
    private String source;
    private String param1; //备用参数
    private String param2; //备用参数
    private String param3; //备用参数
    private Integer machineCount; // 机位数
    private String streamId1; // 一号机位流ID
    private String streamId2; // 二号机位流ID
    private String mainScreenStreamId; // 当前主画面流ID
    private ChatEvent recentSystemComment; // 最近一条系统评论
    private String gifPicture; //动图封面
    /*======================= 视频上传字段 ======================*/
    private Long mid; // 上传视频媒资id
    private Long vid; // 上传视频id
    private Integer videoUploadStatus; // 视频上传状态 -3:转码失败 -2:上传媒资失败 -1:上传失败 0:上传成功 1:上传媒资成功 2:转码成功 default：未初始化
    private Integer videoUploadRole; // 视频上传用户角色 1：用户，2：运营
    private Integer videoUploadReviewStatus; // 视频上传审核状态 -1:审核中 0:审核不通过 1:审核通过
    private Integer isLandscape;//是否横屏：1表示横屏，0表示竖屏
    /**
     * 转录播状态
     *
     * UPLOAD_OVER: 上传完毕
     * PLAY_OK: 可以正常播放
     * OK: 处理成功
     * DEAL_FAILED: 转码失败
     * SOURCE_FAILED: 片源错误
     * PUBLISH_FAILED: 发布失败
     * UPLOAD_FAILED: 上传失败
     * CHECK_FAILED: 审核失败
     */
    private String replayConvertStatus;
    private Integer liveServiceProvider; // 直播服务提供商
    private String tencentChannelId; // 腾讯云频道ID
    private Integer sourceType; // 视频来源 1:乐视云个人直播 2:rtmp直播台 3:TX云直播 4:乐视网hls轮播台 5:云点播 6:上传视频播放 7:TX点播播放
    private ActivityInfo activityInfo; // 直播活动信息
    private List<StreamInfo> videoInfo; // 录播视频信息
    private List<StreamInfo> videoInfoIOS; // IOS用录播视频信息
    private List<StreamInfo> videoInfoAndroid; // Android用录播视频信息
    private Integer pType2;  //节目类型2 1:直播 2:预约 3:点播 4:秒转
    private Integer isPrivacy; // 是否私密 1: 是 0：否
    private List<Map<String, Object>> activityList; // 该视频所属活动列表
    private Integer runMode;  // 运行模式 0:后台运行 1:前台运行

    public ProgramDTO() {

    }
    public ProgramDTO(Program program,UserDTO user){
        this.setUser(user);
        this.setPName(program.getPName());
        this.setLiveInfo(new LiveInfo(ObjectUtils.toString(program.getLiveId())));
        this.setPDesc(program.getPDesc());
        this.setPType(program.getPType());
        // TODO 区分封面图
        if (!"".equals(program.getListPicture())) {

            this.setPicture(program.getListPicture());
        } else {

            this.setPicture(program.getPicture());
        }
//        this.setPicture(program.getPicture());
        this.setStartTime(DateUtils.long2StrDate(program.getStartTime()));
        // TODO v2.2.1
        int carouselFlg = ObjectUtils.toInteger(program.getIsCarousel(), 0);
        // 视频为轮播台时
        if (carouselFlg == 1) {

            // 时长显示为24小时制
            this.setPlayTime(DateUtils.continueSecTime(DateUtils.getDateRange(-1)));
        } else {

            this.setPlayTime(DateUtils.continueSecTime(program.getStartTime()));
        }
        this.setIsCarousel(carouselFlg);
        this.setLikeNum(program.getLikeNum());
        this.setWatchNum(program.getWatchNum());
        this.setCommentNum(program.getCommentNum());
        this.setShareUrl(ProgramConstants.SHARE_URL + program.getId());
        this.setFrom(program.getFrom());
        this.setUgcStatus(program.getStatus());
        this.setProvice(program.getProvince());
        this.setCity(program.getCity());
        if (program.getRecentComment() != null) {

            this.setRecentComment(program.getRecentComment());
        } else {

            this.setRecentComment(new ArrayList<ChatEvent>());
        }
        this.setRecentSystemComment(program.getRecentSystemComment());
        this.setSource(ObjectUtils.toString(program.getSource()));
        this.setMachineCount(ObjectUtils.toInteger(program.getMachineCount(), 1));
        this.setReplayConvertStatus(ObjectUtils.toString(program.getReplayConvertStatus(), ""));
        this.setLiveServiceProvider(ObjectUtils.toInteger(program.getLiveServiceProvider(), Constants.LIVE_SERVICE_PROVIDER_LE));
        this.setTencentChannelId(ObjectUtils.toString(program.getTencentChannelId(), ""));

        String activityInfoStr = ObjectUtils.toString(program.getActivityInfo(), "");
        if (!"".equals(activityInfoStr)) {

            this.setActivityInfo(JSON.parseObject(activityInfoStr, ActivityInfo.class));
        }

        String videoInfoIOSStr = ObjectUtils.toString(program.getVideoInfoIOS(), "");
        if (!"".equals(videoInfoIOSStr)) {

            this.setVideoInfoIOS(JSON.parseArray(videoInfoIOSStr, StreamInfo.class));
        }

        String videoInfoAndroidStr = ObjectUtils.toString(program.getVideoInfoAndroid(), "");
        if (!"".equals(videoInfoAndroidStr)) {

            this.setVideoInfoAndroid(JSON.parseArray(videoInfoAndroidStr, StreamInfo.class));
        }

        this.setSourceType(ObjectUtils.toInteger(program.getSourceType()));
        this.setPrimaryPName(ObjectUtils.toString(program.getPrimaryPName()));
        this.setSource(ObjectUtils.toString(program.getSource(), ""));
        this.setParam1(ObjectUtils.toString(program.getParam1(), ""));
        this.setParam2(ObjectUtils.toString(program.getParam2(), ""));
        this.setParam3(ObjectUtils.toString(program.getParam3(), ""));
        this.setMachineCount(ObjectUtils.toInteger(program.getMachineCount(), 1));
        this.setGifPicture(program.getGifPicture());
        this.setMid(ObjectUtils.toLong(program.getMid()));
        this.setVid(ObjectUtils.toLong(program.getVid()));
        this.setVideoUploadStatus(ObjectUtils.toInteger(program.getVideoUploadStatus()));
        this.setVideoUploadRole(ObjectUtils.toInteger(program.getVideoUploadRole()));
        this.setVideoUploadReviewStatus(ObjectUtils.toInteger(program.getVideoUploadReviewStatus()));
        this.setWatchCount(ObjectUtils.toLong(program.getWatchCount()));
    }

    public ProgramDTO(Program program) {

        if(program.getPType() == 4) {

            if (program.getAct() != null) {

                ActivityDTO activityDTO = new ActivityDTO(program.getAct(), "1");
                this.setActivity(activityDTO);
                this.setPType(program.getPType());

                if (program.getUserRef() != null) {

                    User user = UserConvert.castDBObjectToUser(program.getUserRef().fetch());
                    if (user != null) {
                        UserDTO dto = new UserDTO(user);
                        this.setUser(dto);
                    }
                } else {

                    UserDTO dto = new UserDTO(new User());
                    this.setUser(dto);
                }

            } else {

                this.setPName(program.getPName());
                this.setPicture(program.getPicture());
                this.setPType(program.getPType());
            }

        } else {
            this.setId(program.getId());
            User user = UserConvert.castDBObjectToUser(program.getUserRef().fetch());
            if (user != null) {
                UserDTO dto = new UserDTO(user);
                this.setUser(dto);
            }
            this.setPName(program.getPName());
            this.setPDesc(program.getPDesc());
            this.setPType(program.getPType());
            // TODO 区分封面图
            if (!"".equals(program.getListPicture())) {

                this.setPicture(program.getListPicture());
            } else {

                this.setPicture(program.getPicture());
            }
            this.setBigPicture(program.getBigPicture());

            if (StringUtils.isNotBlank(program.getLiveId())) {
                this.setLiveInfo(new LiveInfo(ObjectUtils.toString(program.getLiveId())));
            } else if (program.getPType() == 3) {
                if (StringUtils.isNotBlank(program.getVuid())) {
                    this.setReplayInfo(new ReplayInfo(ProgramConstants.UUID, program.getVuid()));
                }

                // TODO 时移动播放
                this.setStreamId(program.getActivityId());
            } else {
                this.setStreamId(program.getActivityId());
            }
            this.setStartTime(ObjectUtils.toString(program.getStartTime()));
            if (program.getPType() == 1 || program.getPType() == 2) {
                this.setPlayTime(DateUtils.continueSecTime(program.getStartTime()));
            }
            if (program.getPType() == 3 || program.getPType() == 99) {

                if (program.getPlayTime() > 0L) {

                    this.setPlayTime(ObjectUtils.toString(program.getPlayTime()));
                } else {

                    this.setPlayTime(DateUtils.continueSecTime(program.getStartTime(), program.getEndTime()));
                }

                this.setActionLogUrl(program.getActionLogUrl());
                this.setActionLogVer(program.getActionLogVer());
            }

            // TODO v2.2.1
            int carouselFlg = ObjectUtils.toInteger(program.getIsCarousel(), 0);
            // 视频为轮播台时
            if (carouselFlg == 1) {

                // 时长显示为24小时制
                this.setPlayTime(DateUtils.continueSecTime(DateUtils.getDateRange(-1)));
            }

            this.setIsCarousel(carouselFlg);
            this.setShareUrl(ProgramConstants.SHARE_URL + program.getId());
            this.setLikeNum(program.getLikeNum());
            this.setWatchNum(program.getWatchNum());
            this.setCommentNum(program.getCommentNum());
            this.setFrom(program.getFrom());
            this.setUgcStatus(program.getStatus());
            this.setProvice(ObjectUtils.toString(program.getProvince(), ""));
            this.setCity(ObjectUtils.toString(program.getCity(), ""));
            Long orderNum = ObjectUtils.toLong(program.getOrderNum(), 0L);
            Long displayOrderNum = ObjectUtils.toLong(program.getDisplayOrderNum(), 0L);
            this.setOrderNum(orderNum + displayOrderNum);
            this.setIconUrl(ObjectUtils.toString(program.getIconUrl(), ""));
            this.setCopyWriter(ObjectUtils.toString(program.getCopyWriter(), ""));
            this.setLikeIconUrl(ObjectUtils.toString(program.getLikeIconUrl(), ""));
            this.setLikeIconMd5(ObjectUtils.toString(program.getLikeIconMd5(), ""));
            if (program.getRecentComment() != null) {

                this.setRecentComment(program.getRecentComment());
            } else {

                this.setRecentComment(new ArrayList<ChatEvent>());
            }
            this.setRecentSystemComment(program.getRecentSystemComment());
            this.setReplayConvertStatus(ObjectUtils.toString(program.getReplayConvertStatus(), ""));
            this.setLiveServiceProvider(ObjectUtils.toInteger(program.getLiveServiceProvider(), Constants.LIVE_SERVICE_PROVIDER_LE));
            this.setTencentChannelId(ObjectUtils.toString(program.getTencentChannelId(), ""));

            String activityInfoStr = ObjectUtils.toString(program.getActivityInfo(), "");
            if (!"".equals(activityInfoStr)) {

                this.setActivityInfo(JSON.parseObject(activityInfoStr, ActivityInfo.class));
            }

            String videoInfoIOSStr = ObjectUtils.toString(program.getVideoInfoIOS(), "");
            if (!"".equals(videoInfoIOSStr)) {

                this.setVideoInfoIOS(JSON.parseArray(videoInfoIOSStr, StreamInfo.class));
            }

            String videoInfoAndroidStr = ObjectUtils.toString(program.getVideoInfoAndroid(), "");
            if (!"".equals(videoInfoAndroidStr)) {

                this.setVideoInfoAndroid(JSON.parseArray(videoInfoAndroidStr, StreamInfo.class));
            }

            this.setSourceType(ObjectUtils.toInteger(program.getSourceType()));
            this.setPrimaryPName(ObjectUtils.toString(program.getPrimaryPName()));
            this.setSource(ObjectUtils.toString(program.getSource(), ""));
            this.setParam1(ObjectUtils.toString(program.getParam1(), ""));
            this.setParam2(ObjectUtils.toString(program.getParam2(), ""));
            this.setParam3(ObjectUtils.toString(program.getParam3(), ""));
            this.setMachineCount(ObjectUtils.toInteger(program.getMachineCount(), 1));
            this.setGifPicture(program.getGifPicture());
            this.setMid(ObjectUtils.toLong(program.getMid()));
            this.setVid(ObjectUtils.toLong(program.getVid()));
            this.setVideoUploadStatus(ObjectUtils.toInteger(program.getVideoUploadStatus()));
            this.setVideoUploadRole(ObjectUtils.toInteger(program.getVideoUploadRole()));
            this.setVideoUploadReviewStatus(ObjectUtils.toInteger(program.getVideoUploadReviewStatus()));
            this.setWatchCount(ObjectUtils.toLong(program.getWatchCount()));
            this.setIsLandscape(ObjectUtils.toInteger(program.getIsLandscape()));
        }
    }

    public ProgramDTO(Program program, Integer type, User... users) {

        // 数据同步
        if (type == ProgramConstants.PROGRAM_DTO_TYPE_DATA_SYNC) {

            this.setId(program.getId());
            this.setPName(ObjectUtils.toString(program.getPName(), ""));
            this.setPDesc(ObjectUtils.toString(program.getPDesc(), ""));
            this.setPType(program.getPType());
            this.setUserId(program.getUserId());
            this.setStatus(program.getStatus());
            this.setLocation(ObjectUtils.toString(program.getLocation(), ""));
            this.setProvice(ObjectUtils.toString(program.getProvince(), ""));
            this.setCity(ObjectUtils.toString(program.getCity(), ""));
            this.setPicture(ObjectUtils.toString(program.getPicture(), ""));
            this.setLikeNum(ObjectUtils.toLong(program.getLikeNum(), 0l));
            this.setWatchNum(ObjectUtils.toLong(program.getWatchNum(), 0l));
            this.setCommentNum(ObjectUtils.toLong(program.getCommentNum(), 0l));
            this.setRealLikeNum(ObjectUtils.toLong(program.getRealLikeNum(), 0l));
            this.setRealWatchNum(ObjectUtils.toLong(program.getRealWatchNum(), 0l));
            this.setRealCommentNum(ObjectUtils.toLong(program.getRealCommentNum(), 0l));
            this.setStartTime(ObjectUtils.toString(program.getStartTime(), ""));
            this.setEndTime(ObjectUtils.toLong(program.getEndTime(), 0l));
            this.setCreateTime(ObjectUtils.toLong(program.getCreateTime(), 0l));
            this.setUpdateTime(ObjectUtils.toLong(program.getUpdateTime(), 0l));
            this.setOrderNum(ObjectUtils.toLong(program.getOrderNum(), 0l));
            this.setDisplayOrderNum(ObjectUtils.toLong(program.getDisplayOrderNum(), 0l));
            this.setPriority(ObjectUtils.toLong(program.getPriority(), 0l));
            this.setIsShow(ObjectUtils.toInteger(program.getIsShow(), 1));
            this.setPrimaryPName(ObjectUtils.toString(program.getPrimaryPName(), ""));
            this.setFrom(program.getFrom());
            this.setIsCarousel(ObjectUtils.toInteger(program.getIsCarousel(), 0));
            this.setLiveId(ObjectUtils.toString(program.getLiveId(), ""));
            this.setActivityId(ObjectUtils.toString(program.getActivityId(), ""));
            this.setVideoId(ObjectUtils.toString(program.getVideoId(), ""));
            this.setVuid(ObjectUtils.toString(program.getVuid(), ""));
            this.setIsContinue(ObjectUtils.toInteger(program.getIsContinue(), 0));
            this.setIconUrl(ObjectUtils.toString(program.getIconUrl(), ""));
            this.setCopyWriter(ObjectUtils.toString(program.getCopyWriter(), ""));
            this.setPlayUrl(ObjectUtils.toString(program.getPlayUrl(), ""));
            this.setSource(ObjectUtils.toString(program.getSource(), ""));
            this.setParam1(ObjectUtils.toString(program.getParam1(), ""));
            this.setParam2(ObjectUtils.toString(program.getParam2(), ""));
            this.setParam3(ObjectUtils.toString(program.getParam3(), ""));
            String activityInfoStr = ObjectUtils.toString(program.getActivityInfo(), "");
            if (!"".equals(activityInfoStr)) {

                this.setActivityInfo(JSON.parseObject(activityInfoStr, ActivityInfo.class));
            }
            this.setIsPrivacy(ObjectUtils.toInteger(program.getIsPrivacy()));
            this.setActivityList(program.getActivity());
        } else if (type == ProgramConstants.PROGRAM_DTO_TYPE_INDEX) {

            // 首页
            this.setId(program.getId());
            this.setPType(program.getPType());
            this.setPName(program.getPName());
            this.setPDesc(program.getPDesc());
            this.setGifPicture(program.getGifPicture());
            this.setCity(ObjectUtils.toString(program.getCity(), ""));
            int carouselFlg = ObjectUtils.toInteger(program.getIsCarousel(), 0);
            String playTime = "";
            if (program.getPType() == 1) {

                // 视频为轮播台时
                if (carouselFlg == 1) {

                    // 时长显示为24小时制
                    playTime = DateUtils.continueSecTime(DateUtils.getDateRange(-1));
                } else {

                    playTime = DateUtils.continueSecTime(program.getStartTime());
                }
            } else if (program.getPType() == 3) {

                if (program.getPlayTime() > 0L) {

                    playTime = ObjectUtils.toString(program.getPlayTime());
                } else {

                    playTime = DateUtils.continueSecTime(program.getStartTime(), program.getEndTime());
                }
            } else if (program.getPType() == 99) {

                playTime = ObjectUtils.toString(program.getPlayTime());
            }
            this.setPlayTime(playTime);
            this.setStartTime(ObjectUtils.toString(program.getStartTime()));
            this.setLikeNum(program.getLikeNum());
            this.setCommentNum(program.getCommentNum());
            this.setWatchCount(program.getWatchCount());
            this.setShareUrl(ProgramConstants.SHARE_URL + program.getId());
            this.setMachineCount(ObjectUtils.toInteger(program.getMachineCount(), 1));
            this.setIsCarousel(carouselFlg);
            this.setSourceType(ObjectUtils.toInteger(program.getSourceType()));
            String activityInfoStr = ObjectUtils.toString(program.getActivityInfo(), "");
            if (!"".equals(activityInfoStr)) {

                this.setActivityInfo(JSON.parseObject(activityInfoStr, ActivityInfo.class));
            }

            String userBackgroundPicture = "";
            User user = null;

            if (users != null && users.length > 0) {

                user = users[0];
            } else {

                user = UserConvert.castDBObjectToUser(program.getUserRef().fetch());
            }
            if (user != null) {

                UserDTO userDTO = new UserDTO();

                userDTO.setUserId(user.getUserId());
                userDTO.setNickName(user.getNickName());
                userDTO.setRole(user.getRole());

                String userIcon = Constants.USER_ICON_DEFAULT;
                String pics = user.getPicture();
                if (StringUtils.isNotBlank(pics)) {

                    String[] picArg = pics.split(",");
                    userIcon = picArg[0];
                }
                userDTO.setUserIcon(userIcon);

                this.setUser(userDTO);

                userBackgroundPicture = ObjectUtils.toString(user.getBackgroundPic(), "");
            }

            Integer userRole = program.getUserRole();
            Integer uploadPic = ObjectUtils.toInteger(program.getUploadPic(), 0);
            String picture = program.getPicture();
            String bigPicture = program.getBigPicture();

            // 当用户为主播且是直播时
            if (userRole == Constants.USER_ROLE_HOST && program.getPType() == 1) {

                if (!"".equals(bigPicture)) {

                    picture = bigPicture;
                } else if (!"".equals(userBackgroundPicture)) {

                    picture = userBackgroundPicture;
                } else if (uploadPic == 1 && !picture.equals(Constant.DEFAULT_PICTURE)) {

                    picture = program.getPicture();
                }
            } else {

                if (!"".equals(bigPicture)) {

                    picture = bigPicture;
                } else if (uploadPic == 1 && !picture.equals(Constant.DEFAULT_PICTURE)) {

                    picture = program.getPicture();
                } else if (program.getPType() == 1 && !"".equals(userBackgroundPicture)) {

                    picture = userBackgroundPicture;
                }
            }

            this.setPicture(picture);
            this.setIsLandscape(ObjectUtils.toInteger(program.getIsLandscape()));
        }
    }

    public ProgramDTO(Program program, User user) {

        this.setId(program.getId());
        if (user != null) {
            UserDTO dto = new UserDTO(user);
            this.setUser(dto);
        }
        this.setPName(program.getPName());
        this.setPDesc(program.getPDesc());
        this.setPType(program.getPType());
        // TODO 区分封面图
        if (!"".equals(program.getListPicture())) {

            this.setPicture(program.getListPicture());
        } else {

            this.setPicture(program.getPicture());
        }
        this.setBigPicture(program.getBigPicture());

        if (StringUtils.isNotBlank(program.getLiveId())) {
            this.setLiveInfo(new LiveInfo(ObjectUtils.toString(program.getLiveId())));
        } else if (program.getPType() == 3) {
            if (StringUtils.isNotBlank(program.getVuid())) {
                this.setReplayInfo(new ReplayInfo(ProgramConstants.UUID, program.getVuid()));
            }

            // TODO 时移动播放
            this.setStreamId(program.getActivityId());
        } else {
            this.setStreamId(program.getActivityId());
        }
        this.setStartTime(ObjectUtils.toString(program.getStartTime()));
        if (program.getPType() == 1 || program.getPType() == 2) {
            this.setPlayTime(DateUtils.continueSecTime(program.getStartTime()));
        }
        if (program.getPType() == 3 || program.getPType() == 99) {

            if (program.getPlayTime() > 0L) {

                this.setPlayTime(ObjectUtils.toString(program.getPlayTime()));
            } else {

                this.setPlayTime(DateUtils.continueSecTime(program.getStartTime(), program.getEndTime()));
            }

            this.setActionLogUrl(program.getActionLogUrl());
            this.setActionLogVer(program.getActionLogVer());
        }

        int carouselFlg = ObjectUtils.toInteger(program.getIsCarousel(), 0);
        // 视频为轮播台时
        if (carouselFlg == 1) {

            // 时长显示为24小时制
            this.setPlayTime(DateUtils.continueSecTime(DateUtils.getDateRange(-1)));
        }

        this.setIsCarousel(carouselFlg);
        this.setShareUrl(ProgramConstants.SHARE_URL + program.getId());
        this.setLikeNum(program.getLikeNum());
        this.setWatchNum(program.getWatchNum());
        this.setCommentNum(program.getCommentNum());
        this.setFrom(program.getFrom());
        this.setUgcStatus(program.getStatus());
        this.setProvice(ObjectUtils.toString(program.getProvince(), ""));
        this.setCity(ObjectUtils.toString(program.getCity(), ""));
        Long orderNum = ObjectUtils.toLong(program.getOrderNum(), 0L);
        Long displayOrderNum = ObjectUtils.toLong(program.getDisplayOrderNum(), 0L);
        this.setOrderNum(orderNum + displayOrderNum);
        this.setIconUrl(ObjectUtils.toString(program.getIconUrl(), ""));
        this.setCopyWriter(ObjectUtils.toString(program.getCopyWriter(), ""));
        this.setLikeIconUrl(ObjectUtils.toString(program.getLikeIconUrl(), ""));
        this.setLikeIconMd5(ObjectUtils.toString(program.getLikeIconMd5(), ""));
        if (program.getRecentComment() != null) {

            this.setRecentComment(program.getRecentComment());
        } else {

            this.setRecentComment(new ArrayList<ChatEvent>());
        }
        this.setRecentSystemComment(program.getRecentSystemComment());
        this.setReplayConvertStatus(ObjectUtils.toString(program.getReplayConvertStatus(), ""));
        this.setLiveServiceProvider(ObjectUtils.toInteger(program.getLiveServiceProvider(), Constants.LIVE_SERVICE_PROVIDER_LE));
        this.setTencentChannelId(ObjectUtils.toString(program.getTencentChannelId(), ""));

        String activityInfoStr = ObjectUtils.toString(program.getActivityInfo(), "");
        if (!"".equals(activityInfoStr)) {

            this.setActivityInfo(JSON.parseObject(activityInfoStr, ActivityInfo.class));
        }

        String videoInfoIOSStr = ObjectUtils.toString(program.getVideoInfoIOS(), "");
        if (!"".equals(videoInfoIOSStr)) {

            this.setVideoInfoIOS(JSON.parseArray(videoInfoIOSStr, StreamInfo.class));
        }

        String videoInfoAndroidStr = ObjectUtils.toString(program.getVideoInfoAndroid(), "");
        if (!"".equals(videoInfoAndroidStr)) {

            this.setVideoInfoAndroid(JSON.parseArray(videoInfoAndroidStr, StreamInfo.class));
        }

        this.setSourceType(ObjectUtils.toInteger(program.getSourceType()));
        this.setPrimaryPName(ObjectUtils.toString(program.getPrimaryPName()));
        this.setSource(ObjectUtils.toString(program.getSource(), ""));
        this.setParam1(ObjectUtils.toString(program.getParam1(), ""));
        this.setParam2(ObjectUtils.toString(program.getParam2(), ""));
        this.setParam3(ObjectUtils.toString(program.getParam3(), ""));
        this.setMachineCount(ObjectUtils.toInteger(program.getMachineCount(), 1));
        this.setGifPicture(program.getGifPicture());
        this.setMid(ObjectUtils.toLong(program.getMid()));
        this.setVid(ObjectUtils.toLong(program.getVid()));
        this.setVideoUploadStatus(ObjectUtils.toInteger(program.getVideoUploadStatus()));
        this.setVideoUploadRole(ObjectUtils.toInteger(program.getVideoUploadRole()));
        this.setVideoUploadReviewStatus(ObjectUtils.toInteger(program.getVideoUploadReviewStatus()));
        this.setWatchCount(ObjectUtils.toLong(program.getWatchCount()));
        this.setIsLandscape(ObjectUtils.toInteger(program.getIsLandscape()));
    }

    @Getter
    @Setter
    class LiveInfo {
        private String liveId;
        private Integer isLetv;
        private Integer isHls;

        public LiveInfo() {}

        public LiveInfo(String liveId){
            this.setIsHls(1);
            this.setIsLetv(1);
            this.setLiveId(liveId);
        }
    }

    @Getter
    @Setter
    class ReplayInfo {
        private String uuid;
        private String vuid;

        public ReplayInfo() {}

        public ReplayInfo(String uuid,String vuid){
            this.setUuid(uuid);
            this.setVuid(vuid);
        }
    }

}
